package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsSearchHistoryMapper;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.SearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 15:35
 */
@Service
public class SearchHistoryServiceImpl implements SearchHistoryService {
    @Autowired
    private DtsSearchHistoryMapper dtsSearchHistoryMapper;

    @Override
    public IPage<DtsSearchHistory> findListByQuery(Integer userId, String keyword, String sort, String order, Integer page, Integer limit) {
        return dtsSearchHistoryMapper.selectPage(new Page<DtsSearchHistory>(page,limit),new QueryWrapper<DtsSearchHistory>()
                .eq(!StringUtils.isEmpty(userId),"user_id",userId)
                .like(!StringUtils.isEmpty(keyword),"keyword",keyword)
                .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }


}
